package com.example.myapplication.Outpatientappointment;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.OrdinaryregistrationBean;
import com.example.myapplication.apter.OrdinaryregistrationApter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

public class AdministrativeofficeActivity extends AppCompatActivity {

    private TextView text_administrativeoffice;
    private TextView xxx;
    private String administrativeofficeActivityID;
    private String AdministrativeofficeActivityMoney;
    private String AdministrativeofficeActivityName;
    private TabLayout tab_Administrativeoffice;
    private Button re_Administrativeoffice;
    private Button add_Administrativeoffice;
    private RecyclerView RecyclerViewe_Administrativeoffice;
    private OrdinaryregistrationBean ordinaryregistrationBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_administrativeoffice);
        Intent intent = getIntent();
        administrativeofficeActivityID = intent.getStringExtra("AdministrativeofficeActivityID");
        AdministrativeofficeActivityName = intent.getStringExtra("AdministrativeofficeActivityName");
        AdministrativeofficeActivityMoney = intent.getStringExtra("AdministrativeofficeActivityMoney");
        initview();
        //返回
        bloakAdministrativeoffice();
        //显示专家和普通分类
        tabsort();
        //点击添加预约挂号
        addMakeanappointment();
    }

    //点击添加预约挂号
    private void addMakeanappointment() {
        //点击添加预约挂号
        add_Administrativeoffice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AdministrativeofficeActivity.this, MakeanappointmentActivity.class);
                intent.putExtra("AdministrativeofficeID", administrativeofficeActivityID);
                intent.putExtra("AdministrativeofficeMoney", AdministrativeofficeActivityMoney);
                AdministrativeofficeActivity.this.startActivity(intent);
            }
        });
    }

    private void bloakAdministrativeoffice() {
        re_Administrativeoffice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AdministrativeofficeActivity.this.finish();
            }
        });
    }

    private void tabsort() {
        ArrayList<String> lists = new ArrayList<>();
        lists.add("专家挂号");
        lists.add("普通挂号");
        for (int i = 0; i < lists.size(); i++) {
            TabLayout.Tab tab = tab_Administrativeoffice.newTab();
            tab.setText(lists.get(i));
            tab_Administrativeoffice.addTab(tab);
        }
        tab_Administrativeoffice.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int position = tab.getPosition();
                String TabName = tab.getText().toString();
                if (TabName.equals("专家挂号")) {
                    Expertregistration();
                } else if (TabName.equals("普通挂号")) {
                    ordinaryregistration();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    //专家挂号
    private void Expertregistration() {

    }

    //普通挂号
    private void ordinaryregistration() {
        OKHttpTool.doNetRequest("prod-api/api/hospital/reservation/list", OKHttpTool.GET, OrdinaryregistrationBean.class, new OKHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ordinaryregistrationBean = (OrdinaryregistrationBean)obj;
                        OrdinaryregistrationApter ordinaryregistrationApter = new OrdinaryregistrationApter(AdministrativeofficeActivity.this,ordinaryregistrationBean.getRows());
                        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(AdministrativeofficeActivity.this);
                        RecyclerViewe_Administrativeoffice.setAdapter(ordinaryregistrationApter);
                        RecyclerViewe_Administrativeoffice.setLayoutManager(linearLayoutManager);
                    }
                });

            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void initview() {
        text_administrativeoffice = findViewById(R.id.text_Administrativeoffice);
        RecyclerViewe_Administrativeoffice = findViewById(R.id.RecyclerViewe_Administrativeoffice);
        re_Administrativeoffice = findViewById(R.id.re_Administrativeoffice);
        add_Administrativeoffice = findViewById(R.id.add_Administrativeoffice);
        text_administrativeoffice.setText(AdministrativeofficeActivityName);

        tab_Administrativeoffice = findViewById(R.id.tab_Administrativeoffice);

    }
}